package com.yanqu.road.server.cmd.activity.jieshi;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.JieShiProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.jieshi.JieShiModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_JIESHI_USE_ENERGY_ITEM, desc = "恢复体力")
public class JieShiUseEnergyItemCmd extends AbstractCommand {


    private int count;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        JieShiProto.JieShiRecoveryEnergyReqMsg reqMsg = JieShiProto.JieShiRecoveryEnergyReqMsg.parseFrom(packet.getBytes());
        count = reqMsg.getCount();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(JieShiModule.class).useEnergyItem(count);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            JieShiProto.JieShiRecoveryEnergyRespMsg.Builder respMsg = JieShiProto.JieShiRecoveryEnergyRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_JIESHI_USE_ENERGY_ITEM, respMsg);
        }
    }
}
